import type { AddressItem, IAddress } from "@/types/address"
import { http } from "@/utils/request"

/**
 *  新增收货地址
 * @param data 
 * @returns Promise<{ id: string }>
 */
export const addAddressAPI = (data: IAddress) => {
  return http<{ id: string }>({
    url: '/member/address',
    method: 'POST',
    data
  })
}

/**
 * 获取收货地址列表
 */
export const getMemberAddressAPI = () => {
  return http<AddressItem[]>({
    method: 'GET',
    url: '/member/address',
  })
}
/**
 * 获取收货地址详情
 * @param id 
 */
export const getMemberAddressDetail = (id: string) => {
  return http<AddressItem>({
    method: 'GET',
    url: `/member/address/${id}`
  })
}
/**
 * 修改收货地址
 * @param id 
 * @param data 
 */
export const updateAddressAPI = (id: string, data: IAddress) => {
  return http({
    method: 'PUT',
    url: `/member/address/${id}`,
    data
  })
}
/**
 * 删除收货地址
 * @param id  
 * @returns 
 */
export const delMemberAdressAPI = (id: string) => {
  return http({
    method: 'DELETE',
    url: `/member/address/${id}`
  })
}